package com.lgd.btw.demo.controller;

import com.lgd.btw.demo.pojo.Student;
import com.lgd.btw.demo.pojo.User;
import com.lgd.btw.demo.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class MyController {
    @Autowired
    UserService userService;
    @ResponseBody
    @GetMapping("getbyid")
    public User getById(@RequestParam("id") int id){
        return userService.selectById(id);
    }

    @ResponseBody
    @GetMapping("condition")
    public List<User> getByUsername(@RequestParam("username")String username){
        return  userService.getByUsername(username);
    }

    @ResponseBody
    @GetMapping("delete")
    public int delete(@RequestParam("list")List<Integer> list){
        return  userService.delete(list);
    }

    //这里按照result风格应该用post，但是忘了，所以用get了
    @ResponseBody
    @GetMapping("update")
    public int update(){
        User user = new User();
        user.setId("35");
        user.setUsername("aaaaaaa");
        return userService.update(user);
    }


    @ResponseBody
    @GetMapping("insert")
    public int insert(){
        User user = new User();
        user.setUsername("aaaa");
        user.setPassword("aaaa");
        user.setEmail("aaaa@lgd.com");
        return userService.insert(user);
    }

    @ResponseBody
    @GetMapping("selectSD")
    public List<Student> selectSD(){

        return userService.selectSD();
    }


}
